/*
 * Copyright (c) 2009, Takashi Ito
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the authors nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include "sys/queue.h"
#include "tssp.h"
#include "tssp_table.h"

#ifndef _TSSP_DVB_AIT_H_
#define _TSSP_DVB_AIT_H_

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

struct tssp_dvb_ait_app {
    uint32_t org_id;        /**< organization_id */
    uint16_t app_id;        /**< application_id */
    uint8_t control_code;   /**< application_control_code */
    struct tssp_descriptors descriptors; /**< application descriptor loop */

    STAILQ_ENTRY(tssp_dvb_ait_app) entry; /**< Only for internal use, do not access. */
};

STAILQ_HEAD(tssp_dvb_ait_apps, tssp_dvb_ait_app);

struct tssp_dvb_ait {
    uint8_t test_flag;                   /**< test_application_flag */
    uint16_t application_type;           /**< application_type */
    uint8_t version;                     /**< version_number */
    uint8_t current_next;                /**< current_next_indicator */

    struct tssp_descriptors descriptors; /**< common loop */
    struct tssp_dvb_ait_apps apps;       /**< application loop */
};

struct tssp_dvb_ait_monitor;

typedef
void (*tssp_dvb_ait_monitor_callback)(struct tssp_dvb_ait_monitor *monitor,
                                      struct tssp_dvb_ait *ait,
                                      struct tssp_section *section,
                                      void *userdata);

struct tssp_dvb_ait *tssp_dvb_ait_parse(const struct tssp_section *section);
struct tssp_dvb_ait *tssp_dvb_ait_create();
void tssp_dvb_ait_destroy(struct tssp_dvb_ait *ait);
struct tssp_dvb_ait_app *tssp_dvb_ait_add_app(struct tssp_dvb_ait *ait,
                                              uint32_t org_id,
                                              uint16_t app_id,
                                              uint8_t control_code);

void tssp_dvb_ait_app_destroy(struct tssp_dvb_ait_app *ait_app);

struct tssp_dvb_ait_monitor *
tssp_dvb_ait_monitor_attach(struct tssp *parser,
                            uint16_t pid,
                            uint16_t application_type,
                            tssp_dvb_ait_monitor_callback callback,
                            void *userdata);
void tssp_dvb_ait_monitor_detach(struct tssp_dvb_ait_monitor *monitor);
void tssp_dvb_ait_monitor_reset(struct tssp_dvb_ait_monitor *monitor);

#ifdef __cplusplus
};
#endif /* __cplusplus */

#endif /* _TSSP_DVB_AIT_H_ */

